package com.xiangyu.demo.configuration.jms;

import com.xiangyu.demo.bean.UserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.stereotype.Service;

import javax.jms.Destination;
import javax.jms.ObjectMessage;
import javax.jms.Session;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

/**
 * java类简单作用描述
 *
 * @ProjectName: springboot-demo
 * @Package: com.xiangyu.demo.configuration.jms
 * @Description: java类作用描述
 * @Author: 向羽
 * @CreateDate: 2018/1/29 10:37
 * @UpdateUser: 向羽
 * @UpdateDate: 2018/1/29 10:37
 * @UpdateRemark: The modified content
 * @Version: 2.0
 */
@Service("producer")
public class Producer {
    @Autowired
    private JmsMessagingTemplate  jmsMessagingTemplate ;

    // 发送消息，destination是发送到的队列，message是待发送的消息
    public void sendStringMessage(Destination destination, final String message){
        jmsMessagingTemplate.convertAndSend(destination, message);
    }

    public void sendObjectMessage(Destination destination,final Serializable object){
        Map<String, Object> headers =new HashMap();
        headers.put("type",1);
        jmsMessagingTemplate.convertAndSend(destination,object,headers);
    }

}
